import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../models/home_room_entity.dart';

class HouseItem extends StatefulWidget {
  HouseItem(
    this._house, {
    this.isCurrentHouse,
    this.onTap,
  }) : super(key: ValueKey(_house.roomId));
  final HomeRoomObjList _house;
  final bool? isCurrentHouse;
  final GestureTapCallback? onTap;

  @override
  State<StatefulWidget> createState() {
    return _HouseItemState();
  }
}

class _HouseItemState extends State<HouseItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: 96.h,
      padding: EdgeInsets.only(left: 32.w, right: 24.w),
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(16.w), color: Colors.white),
      child: Row(
        children: [
          Visibility(
              visible: widget.isCurrentHouse ?? false,
              child: Padding(
                padding: EdgeInsets.only(right: 24.w),
                child: Image(
                  width: 48.w,
                  height: 48.h,
                  image: const AssetImage("assets/images/me_icon_my_house.png"),
                ),
              )),
          Expanded(
              child: Text(
            (widget._house.communityName) +
                (widget._house.buildingName) +
                (widget._house.unitName) +
                (widget._house.unitName) +
                (widget._house.roomName),
            style: TextStyle(fontSize: 32.sp, color: const Color(0xFF333333)),
          )),
          Visibility(
            visible: !(widget.isCurrentHouse ?? false),
            child: Padding(
              padding: EdgeInsets.only(left: 4.w),
              child: TextButton(
                onPressed: widget.onTap,
                style: TextButton.styleFrom(
                  minimumSize: Size.zero,
                  padding: EdgeInsets.all(16.w),
                  tapTargetSize: MaterialTapTargetSize.shrinkWrap,
                ),
                child: Text(
                  "切换",
                  style: TextStyle(
                      fontSize: 28.sp, color: const Color(0xFF1774E0)),
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
